import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class employee implements Comparable<employee>{
	 Integer id;
	 String address;
	 Character gender;
	employee(Integer id,String add,char gen){
		this.id=id;
		this.address=add;
		this.gender=gen;
	}
	public Integer getid()
	{
		return this.id;
	}
	public void setid(Integer id){
		this.id=id;
	}
	public String getadd()
	{
		return this.address;
	}
	public Character getgender()
	{
		return this.gender;
	}
	public void setadd(String add){
		this.address=add;
	}
	public void setgender(char gen){
		this.gender=gen;
	}
	
	@Override
	public int compareTo(employee e1) {
		// TODO Auto-generated method stub
		//return address.compareTo(e1.getadd());
		//return id.compareTo(e1.getid());
		return gender.compareTo(e1.getgender());
	}
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return this.address+" "+this.id+" "+this.gender;
	}

	
	 }

public class collections {
	//using static array
	public static int[] staticInsert(int a[],int p,int e){
		int[] a2=new int[a.length+1];
		for(int i=0;i<p;i++){
			a2[i]=a[i];
		}
		a2[p]=e;
		for(int i=p+1,j=p;i<a.length+1;i++,j++){
			a2[i]=a[j];
		}
		return a2;
	}
	//dynamic array using arraylist
	public static ArrayList<Integer> arraylistDemo(int a[],int p,int e){
		ArrayList<Integer> al = new ArrayList<Integer>();
		for(int i=0;i<a.length;i++){
		al.add(i,a[i]);
		}
		al.add(p,e);
		return al;
	}
	public static void main(String args[]){
		int[] arr1={10,20,30,40};
		int[] result=staticInsert(arr1,2,25);
		for(int i=0;i<result.length;i++){
			System.out.println(result[i]+" ");
		}
		System.out.println("array list demo\n");
		ArrayList<Integer> al2 =arraylistDemo(arr1,2,25);
		for(int i=0;i<al2.size();i++){
			System.out.println(al2.get(i)+" ");			
		
	}
		//example 3
		{
		Byte b1=10;
		List<Number> los=new ArrayList<Number>();
	    los.add(new Short((short) 1));
	    los.add(new Byte(b1));
	    los.add(new Integer(1046598367));
	    los.add(new Long(1036496));
		los.add(new Double(10.74356783));
		los.add(new Float(10.376));
		System.out.println(los);
		}
		//example 4 
		// scientist sorting
	{
			ArrayList<String> scientist=new ArrayList<String>();
			scientist.add("Peter Neumann");
			scientist.add("Thompson");
			scientist.add("Ritchie");
			scientist.add("Donn Seeley");
			scientist.add("Mike Karels");
			scientist.add("Bill Jolitz");
			scientist.add("Trent Hein");
			//System.out.println("unsorted:"+scientist);
			Collections.sort(scientist);
			//System.out.println("sorted:"+scientist);
		}
		//employees sort by id
		{
			ArrayList<employee>emplist=new ArrayList<employee>();
		emplist.add(new employee(13,"blore",'f'));
		emplist.add(new employee(11,"mysore",'m'));
		emplist.add(new employee(15,"hubli",'m'));
		emplist.add(new employee(10,"hybrabad",'f'));
		System.out.println("unsorted:"+emplist);
		Collections.sort(emplist);
		System.out.println("sorted:"+emplist);
		
		}
			
			
			
	}

  }
